class Trait < ActiveRecord::Base
  validates_presence_of :name
  has_many  :trait_effects
  
  def total_modifier (character_attribute)
    @total_modifier  = 0
    self.trait_effects.each do |value|
      if value.character_attribute == character_attribute
        @total_modifier += value.modifier
      end
      
    end
    
    return @total_modifier
  end
  
  def special_case? (special_case)
    self.trait_effects.each do |value|
      if value.special_case == special_case
        return true
      end
    end
    return false
  end
  
  def Trait.categories
    {
    1 => "Body",
    2 => "Soul",
    3 => "Education: Military",
    4 => "Education: Ecclesiastical",
    5 => "Education: Court",
    6 => "Virtue",
    7 => "Sin"
    }
  end
  
  def Trait.find_all_body
    return Trait.find_all_by_category 1
  end
  
  def Trait.find_all_soul
    return Trait.find_all_by_category 2
  end
  
  def Trait.find_all_military_education
    return Trait.find_all_by_category 4
  end
  
  def Trait.find_all_ecclesiastical_education
    return Trait.find_all_by_category 5
  end
  
  def Trait.find_all_court_education
    return Trait.find_all_by_category 6
  end
  
  def Trait.find_all_virtues
    return Trait.find_all_by_category 7
  end
  
  def Trait.find_all_sins
    return Trait.find_all_by_category 8
  end
  
  def category_name
    Trait.categories[self.category]
  end
end
